package com.leyou.auth.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.auth.entity.ClientInfo;
import com.leyou.auth.mapper.ClientMapper;
import com.leyou.auth.service.ClientService;
import com.leyou.common.exception.LyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;


@Service
public class ClientServiceImpl extends ServiceImpl<ClientMapper, ClientInfo> implements ClientService {

    @Autowired
    public PasswordEncoder passwordEncoder;

    @Value("${ly.jwt.key}")
    public String key;

    @Override
    public String checkClient(String clientId, String secret) {

        ClientInfo clientInfo = this.query().eq("client_id", clientId).one();

        //clientInfo为空,或者密码不匹配 报异常
        if (null==clientId || !passwordEncoder.matches(secret,clientInfo.getSecret())){

            throw new LyException(403,"输入非法,拒绝请求");

        }
      return key;

    }
}